#HEALTH OF ONLINE COMMUNITIES
#addTenure.py
#
#
#Takes in tab separated data of form user->Timestamp->Namespace and appends each line with
#	time of user's first and last edit 
#
#Output format:
#User + Timestamp of edit + Namespace of edit + time of first edit + time of last edit

import sys
import datetime

def main():
	
	user = None
	dateList = []
	firstUser = 0

	for line in sys.stdin:
		pieces = line.split('\t')
		username = pieces[0]
		
		if username <> user:
			if firstUser <> 0:
				lastDate = date		
				printStuff(user,firstDate,lastDate,dateList)
				
			firstDate = convertTime(pieces[1].replace('Z',''))
			dateList = [] 
			
	
		user = username
		date = convertTime(pieces[1].replace('Z',''))
		dateList.append([date,pieces[2]])	
		firstUser = 1
	
	lastDate = date
	printStuff(user,firstDate,lastDate,dateList)

#converts UTC time into datetime
def convertTime(input):
	times = input.split('T')
        date = times[0]
        time = times[1]
        
        dateOb = date.split('-')
        year = int(dateOb[0])
        month = int(dateOb[1])
        day = int(dateOb[2])

        timeOb = time.split(':')
	hour = int(timeOb[0])
        minute = int(timeOb[1])
        second = int(timeOb[2])

        date = datetime.datetime(year,month,day,hour,minute,second)
	return date

def printStuff(username, firstDate, lastDate, dateList):
	for edit in dateList:
		print '\t'.join([username, str(edit[0]), str(edit[1].replace('\n','')), str(firstDate), str(lastDate)])
		

	


main()
